//
//  NormalFormatter.m
//  Conference Track Management
//
//  Created by Jiang on 2018/10/31.
//  Copyright © 2018 jiang. All rights reserved.
//

#import "TimeFormatter.h"
@interface TimeFormatter()
@property (nonatomic, copy)NSString *format;
@end
@implementation TimeFormatter
+ (instancetype)twelveFormatter{
    return [[self alloc] initWithTimeFormat:@"%I:%M %p"];
}
+ (instancetype)tweentyFourFormatter{
    return [[self alloc] initWithTimeFormat:@"%H:%M"];
}
- (instancetype)initWithTimeFormat:(NSString *)format{
    self = [super init];
    self.format = format;
    return self;
}
- (NSString *)timeStampForStartHour:(int)startHour interval:(int)interval{
    struct tm timeinfo;
    memset(&timeinfo, 0, sizeof(struct tm));
    timeinfo.tm_hour = startHour;
    timeinfo.tm_year = 2018 - 1900;
    int len = 256;
    char buffer[len];
    time_t start_interval = timegm(&timeinfo);
    time_t current_interval = start_interval + interval;
    struct tm *ti = gmtime(&current_interval);
    memset(buffer, 0, len);
    strftime (buffer,len,self.format.UTF8String,ti);
    return [NSString stringWithUTF8String:buffer];
}
@end
